package spring.cloud.tasks.client.item_task_processor.task_items_processor;


public class Signal {
    //synchronized object
    private Object object = new Object();
    private int threadCount = 0;

    public Signal() {
    }

    public void waitBeAwakened() throws Exception {
        synchronized (object) {
            this.object.wait();//
        }
    }

    public void notifyOtherThreadsBeAwakened() throws Exception {
        synchronized (object) {
            this.object.notifyAll();
        }
    }

    public void increaseThreadCount1() {
        synchronized (this) {
            threadCount = threadCount + 1;
        }
    }

    public void decreaseThreadCount1() {
        synchronized (this) {
            threadCount = threadCount - 1;
        }
    }


    public boolean decreaseThreadCount1IfThreadCountNotEqual1AndReturnWhetherThreadCountIsNot1() {
        synchronized (this) {
            if (this.threadCount == 1) {
                return false;
            } else {
                threadCount = threadCount - 1;
                return true;
            }
        }
    }


}
